<?php

namespace MemberUser\Controller;
use Common\Controller\MemberUserApiBaseController;
/**
 * 认证控制器
 */
class AppController extends MemberUserApiBaseController{
 
    /**
     * 个人中心首页
     * 
     */
    public function index(){
    	// $map['id']=$_SESSION['member_user'][id];
    	// $data=M('MemberUsers')->where($map)->find();
    	// $assign=array(
     //        	'site_name_tj'=>C('SITE_NAME_TJ'),
     //            'data'=>$data
     //            );
     //        $this->assign($assign);
    	$this->display();
    	
    }
    public function login_check(){
        if (!check_login_member()) {
            $callback = $_REQUEST ['_c']; 
            $res = array('url' =>U('MemberUser/App/login') ,'test' =>'need_login' );
            jsonp_return($res,'您需要登录!',0,'',$callback);

        } else {
        
        $callback = $_REQUEST ['_c']; 
        $res = array('url' =>U('MemberUser/App/index') ,'test' =>'login_success' );
        jsonp_return($res,'您已经登录',1,'',$callback);
            }
    }
    public function get_user_info(){
        if (!check_login_member()) {
            $callback = $_REQUEST ['_c']; 
            $res = array('url' =>U('MemberUser/App/login') ,'test' =>'need_login' );
            jsonp_return($res,'您需要登录!',0,'',$callback);

        } else {
    	$map['id']='88';
    	$data=M('MemberUsers')->where($map)->find();
    	$callback = $_REQUEST ['_c']; 
        $res = array('url' =>U('MemberUser/App/index') ,'test' =>'user_info' );
        jsonp_return($data,'获取用户信息',1,'',$callback);
            }
    }
    public function login(){
        if(IS_POST){
            $map=I('post.');
            $map['password']=md5($map['password']);
            $data=M('MemberUsers')->where($map)->find();
            if (empty($data)) {
                //$this->error('账号或密码错误');
                $callback = $_REQUEST ['_c']; 
                $res = array('url' =>U('MemberUser/App/index') ,'test' =>'wrong_pass' );
               
                //$cbk=phpjsonp($res,'账号或密码错误！',1);
                //echo $callback . '(' . $cbk .')';
                jsonp_return($res,'账号或密码错误！',0,'',$callback);
                
            }else{
                $_SESSION['member_user']=array(
                    'id'=>$data['id'],
                    'username'=>$data['username'],
                    'avatar'=>$data['avatar']
                    );
                //$this->success('登录成功、前往管理后台',U('MemberUser/Index/index'));
                $callback = $_REQUEST ['_c']; 
                $res = array('url' =>U('MemberUser/App/index'),'test' =>'login_success' );
                //$cbk=phpjsonp($res,'登录成功、前往管理后台！',1);
                //$cbk=json_encode($res,JSON_UNESCAPED_UNICODE);
               // echo $callback . '(' . $cbk .')';
                jsonp_return($res,'登录成功、前往个人中心！',1,'',$callback);
            }
       
	}
}
    /**
     * 退出
     */
    public function logout(){
        session('member_user',null);
        //$this->success('退出成功、前往登录页面',U('MemberUser/Index/login'));
        $callback = $_REQUEST ['_c']; 
                $res = array('url' =>U('MemberUser/App/login'),'test' =>'logout' );
        jsonp_return($res,'退出成功、前往登录页面！',0,'',$callback);

    }

	public function message(){
		$this->display();
	}
	public function home(){
		$this->display();
		
	}
	public function set(){
		$this->display();
		
	}

}
